//
//  LBHomeViewController.m
//  01.SinaWeibo
//
//  Created by Label on 12/12/15.
//  Copyright © 2015 Label. All rights reserved.
//

#import "LBHomeViewController.h"
#import "LBTestTableViewController.h"
#import "LBTestViewController.h"
#import "LBDropDownMenu.h"
#import "LBHomeButton.h"

@interface LBHomeViewController ()
//@property (strong, nonatomic)  LBTestTableViewController *viewController;
@end

@implementation LBHomeViewController

- (void)viewDidLoad {
        [super viewDidLoad];
        // 1. 自定义导航栏；
        // 1.1 自定义NavigationItem->leftBarButtonItem；
        self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(friendSearch) Image:@"navigationbar_friendsearch" HighLightedImage:@"navigationbar_friendsearch_highlighted"];
        // 1.2 自定义NavigationItem->rightBarButtonItem；
        self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithTarget:self Action:@selector(pop) Image:@"navigationbar_pop" HighLightedImage:@"navigationbar_pop_highlighted"];
        // 1.3 自定义NavigationItem->titleView；
        LBHomeButton *homeTitleButton = [[LBHomeButton alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
        [homeTitleButton.titleLabel setTextAlignment:NSTextAlignmentCenter];
        [homeTitleButton.titleLabel setFont: [UIFont boldSystemFontOfSize:15]];
        [homeTitleButton setTitle:@"首页" forState:UIControlStateNormal];
        [homeTitleButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [homeTitleButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
        [homeTitleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateNormal];
        [homeTitleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationItem setTitleView:homeTitleButton];
    
    
}

- (void)titleClick:(UIButton *)sender {
        // 1. 创建下拉菜单；
        LBDropDownMenu *menu = [[LBDropDownMenu alloc] init];
        // 2. 添加子视图；
        // UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
        // [menu addContentView:tableView];
        // 2. 添加子视图控制器；
        LBTestTableViewController *viewController = [[LBTestTableViewController alloc] init];
        [viewController.view setFrame:CGRectMake(0, 0, 320, 44*3)];
        [menu addContentViewController:viewController];
        [menu showFrom:sender];
}

- (void)friendSearch {
    NSLog(@"Friend Search!");
}

- (void) pop {
    NSLog(@"Pop");
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"home"];
    [cell.textLabel setText:@"Home"];
    
    // Configure the cell...
    
    return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LBTestViewController *test = [[LBTestViewController alloc] init];
    [test.view setBackgroundColor:LBRandomColor];
    
    [self.navigationController pushViewController:test animated:YES];
}

@end
